package com.example.casper.Experiment2024.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter4.BaseQuickAdapter;
import com.chad.library.adapter4.viewholder.QuickViewHolder;
import com.example.casper.Experiment2024.R;

import java.io.File;

public class PhotoAdapter extends BaseQuickAdapter<String, QuickViewHolder> {

    @Override
    protected void onBindViewHolder(@NonNull QuickViewHolder quickViewHolder, int i, @Nullable String s) {
        ImageView image = quickViewHolder.getView(R.id.image);
        if ("-".equalsIgnoreCase(s)) {
            image.setImageResource(R.drawable.baseline_add_a_photo_24);
        } else {
            Context context = image.getContext();
            Glide.with(context).load(new File(s)).into(image);
        }
    }

    @NonNull
    @Override
    protected QuickViewHolder onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_image, viewGroup, false);
        return new QuickViewHolder(view);
    }
}
